//添加多个参数注意使用[]
layui.use(['form', 'jquery'], function () {

    var form = layui.form,
        $ = layui.jquery;


    var id = sessionStorage.getItem("roleId");
    findById(id);

    /**
     * 查询单个
     * @param id
     */
    function findById(id) {

        let result = commonAjax('/role/findById',{id:id},'get');
        setData(result.data);
    }

    /**
     * 赋值
     */
    function setData(data) {
        $('#id').val(data.id);
        $('#roleName').val(data.roleName);
        $('input[name=dataEnable][value=' + data.dataEnable + ']').next().click();
        $('#sequence').val(data.sequence);

        //刷新单选框样式
        form.render();
    }

    /**
     * 保存  //监听提交
     */
    form.on('submit(commit)', function (data) {
        let formData = JSON.stringify(data.field);

        let result = commonAjax('/role/update',formData,'post');
        if (result.count === 1) {
            layerMsgSaveSuccess();
        } else {
            layerMsgSaveFail();
        }

        return false;
    });


});